﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using UIWindows.Commands;
using UIWindows.Domains;
using UIWindows.GlobalStatics;
using XingLucifer.Devices;
using XingLucifer.IBase.Enums;

namespace UIWindows.ViewModels.Dialogs
{
    public class WeighingDialogViewModel
    {
        public GlobalStatics.ParameterStatic Parameter { get; set; }
        //private DeviceConfigStatic _deviceConfig;
        public WeighingDialogViewModel(GlobalStatics.ParameterStatic _parameter) 
        {
            Parameter= _parameter;
            //_deviceConfig = ObjectContainer.ResolveSingleton<DeviceConfigStatic>();
        }

        public DelegateCommand<object> CloseDialogCommand => new DelegateCommand<object>(parameter => {


//            var plc = _deviceConfig.DeviceList.FirstOrDefault(t => t.DeviceType == DeviceTypes.CIP_Omron && t.ServiceName == "注液机");
//#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型。
//            if (plc == null) {
//                MessageBox.Show("请先运行！！！");
//                return; 
//            }
//            OmronCIP omronCIP = plc.Communication as OmronCIP;
//            var weighingType = Parameter.WeighingConfig.ScaleType == TaskTypes.前称重 ? 1 : 2;
//            //1前称 2后称
//            omronCIP.WriteSingle((float)weighingType, "PC_Result_Scales.BeforeWeight[3].PLCData");

            Parameter.Save();
            // 关闭弹窗的代码
            if (parameter is UserControl userControl)
            {
                MaterialDesignThemes.Wpf.DialogHost.CloseDialogCommand.Execute(null, userControl);
            }
        });
    }
}
